package cn.stylefeng.guns.modular.gridsystem.controller;

import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.gridsystem.entity.BizUploadScore;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.stylefeng.guns.modular.gridsystem.service.BizUploadScoreService;
import cn.stylefeng.guns.modular.gridsystem.model.param.BizUploadScoreParam;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 网关上报分数表 控制器
 *
 * @author: ssy
 * @date: 2021/09/14 11:47
 */
@RestController
public class BizUploadScoreController {

    @Resource
    private BizUploadScoreService bizUploadScoreService;

    /**
     * 分页查询网关上报分数表
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @GetMapping("/bizUploadScore/page")
    public ResponseData page(BizUploadScoreParam bizUploadScoreParam) {
        return new SuccessResponseData(bizUploadScoreService.pageList(bizUploadScoreParam));
    }

    /**
     * 获取全部网关上报分数表
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @GetMapping("/bizUploadScore/list")
    @BusinessLog(title = "网关上报分数表_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(BizUploadScoreParam bizUploadScoreParam) {
        return new SuccessResponseData(bizUploadScoreService.list(bizUploadScoreParam));
    }

    /**
     * 查看详情网关上报分数表
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @GetMapping("/bizUploadScore/detail")
    @BusinessLog(title = "网关上报分数表_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(BizUploadScoreParam.detail.class) BizUploadScoreParam bizUploadScoreParam) {
        return new SuccessResponseData(bizUploadScoreService.detail(bizUploadScoreParam));
    }

    /**
     * 添加网关上报分数表
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @PostMapping("/bizUploadScore/add")
    @BusinessLog(title = "网关上报分数表_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(BizUploadScoreParam.add.class) BizUploadScoreParam bizUploadScoreParam) {
        bizUploadScoreService.add(bizUploadScoreParam);
        return new SuccessResponseData();
    }

    /**
     * 删除网关上报分数表
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @PostMapping("/bizUploadScore/delete")
    @BusinessLog(title = "网关上报分数表_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(BizUploadScoreParam.delete.class) BizUploadScoreParam bizUploadScoreParam) {
        bizUploadScoreService.delete(bizUploadScoreParam);
        return new SuccessResponseData();
    }

    /**
     * 编辑网关上报分数表
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @PostMapping("/bizUploadScore/edit")
    @BusinessLog(title = "网关上报分数表_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(BizUploadScoreParam.edit.class) BizUploadScoreParam bizUploadScoreParam) {
        bizUploadScoreService.edit(bizUploadScoreParam);
        return new SuccessResponseData();
    }

    /**
     * 获取全部网关上报分数表
     *
     * @author ssy
     * @date 2021/09/14 11:47
     */
    @GetMapping("/bizUploadScore/getUploadScoreList")
    public ResponseData getUploadScoreList(BizUploadScoreParam bizUploadScoreParam) {
        List<BizUploadScore> uploadScoreList = bizUploadScoreService.getUploadScoreList(bizUploadScoreParam);
        ArrayList<Double> scoreList = new ArrayList<>();
        for (BizUploadScore uploadScore:uploadScoreList){
            scoreList.add(Double.parseDouble(uploadScore.getScore()));
        }
        return new SuccessResponseData(scoreList);
    }

}
